package com.ruoyi.factory.fanbi.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.factory.fanbi.service.LoginHandleService;
import com.ruoyi.factory.fanbi.utils.FanruanbiloginUtils;
import com.ruoyi.factory.ykj.service.LoginByCodeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.util.Map;

@Service
public class LoginHandleServiceImpl implements LoginHandleService {
    protected final Logger logger = LoggerFactory.getLogger(LoginHandleServiceImpl.class);

    @Autowired
    private LoginByCodeService loginByCodeService;
    @Override
        public AjaxResult getInfoByCode(Map<String,String> request){
        AjaxResult infoByCode = loginByCodeService.getInfoByCode(request);
        if(200 == (int)infoByCode.get("code")){
            SysUser user = (SysUser)infoByCode.get("data");
            String userName = user.getUserName();
            try {
                String getuserens = FanruanbiloginUtils.getuserens(userName);
                return new AjaxResult(200,"success",getuserens);
            } catch (UnsupportedEncodingException e) {
                logger.error(e.getMessage());
            }

        }
        return new AjaxResult(500,"error");

    }
}
